/**
 * 面包自由行 App 内网页交互接口
 **/
var btShowBottomBar;  // 'YES' or 'NO'
var shrFlag; // iOS WebView share button '1' or '0'
var shrUrl; // 微信分享 url
var goBackFlag; // Display back button true or false  
var contactFlag; // Display contact button true or false
var confirmFlag; // Display confirm button true or false

var breadtripBannerTitle;

var vAppSchema = {
    UA: $('body').data('user-agent'), // 0.default 1.iPhone 2.iPad 3.iPod 4.Android
    VARSION: $('body').attr('data-version').replace('&#39;','').replace(/[\[\]']+/g,'').split('_', 2)[1], // '2.1.2'
    setOrderType: function (orderState) {
    /**
     * 设置订单状态
     *
     * @param {number} orderState 订单状态
     **/
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.setOrderType(parseFloat(orderState));
            }
        }
    },
    setOrderId: function (orderId) {
    /**
     * 设置订单Id
     *
     * @param {number} orderId 订单 ID
     **/
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.setOrderId(parseFloat(orderId));
            }
        }
    },
    goBackApp: function (shouldGoBackApp) {
    /**
     * 是否返回App
     *
     * @param {boolean} shouldGoBackApp 是否返回App
     **/
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("goBackApp", [shouldGoBackApp]);
            } else if (this.UA === 4) {
                android.goBackApp(shouldGoBackApp);
            }
        }
    },
    setOrderDate: function (orderDate) {
    /**
     * 设置订单⽇日期
     * 
     * @param {string} OrderDate 订单日期
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.setOrderDate(orderDate);
            }
        }
    },
    goApp: function () {
    /**
     * 返回 App
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.goApp();
            }
        }
    },
    lookOrderList: function () {
    /**
     * 查看订单列表
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("lookOrderList");
            } else if (this.UA === 4) {
                android.lookOrderList();
            }
        }
    },
    goBookingHotel: function (hotelType) {
    /**
     * 选择候⻋车酒店
     *
     * @param {string} hotelType 酒店类型
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("gobookinghotel", [hotelType], function (response){
                    this.setHotelName(hotelType, response);
                });
            } else if (this.UA === 4) {
                android.goBookingHotel(hotelType);
            }
        }
    },
    setTitle: function (title) {
    /**
     * 设置标题
     *
     * @param {string} title 标题
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("setTitle", [title]);
            } else if (this.UA === 4) {
                android.setTitle(title);
            }
        }
    },
    showNewSetTimePicker: function (name, hour, minute) {
    /**
     * 显⽰示设置时间弹窗
     *
     * @param {number} hour   小时
     * @param {number} minute 分钟
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.showNewSetTimePicker(name, parseFloat(hour), parseFloat(minute));
            }
        }
    },
    showSetDatePicker: function (date, type) {
    /**
     * 显⽰设置日期弹窗
     *
     * @param {string} date 日期
     * @param {string} type 分类
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.showSetDatePicker(date, minute);
            }
        }
    },
    goBackURL: function (url) {
    /**
     * 设置后退 URL
     *
     * @param {string} url 后退网址
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.goBackURL(url);
            }
        }
    },
    showContactUs: function (isShow) {
    /**
     * 显⽰示联系我们按钮
     *
     * @param {boolean} isShow 联系我们
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("showContactUs", [isShow]);
            } else if (this.UA === 4) {
                android.showContactUs(isShow);
            }
        }
    },
    showConfirmButton: function(isShow){
    /**
     * 显⽰确认选择按钮
     *
     * @param {boolean} isShow 确认选择
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call("showConfirmButton", [isShow]);
            } else if (this.UA === 4) {
                android.showConfirmButton(isShow);
            }
        }
    },
    goPoiDetail: function (poiName, poiNetId, isBooking, webSite, mtuId) {
    /**
     * 显⽰ POI 详情⻚页
     *
     * @param {string}  poiName   POI 名字
     * @param {number}  poiNetId  POI ID
     * @param {boolean} isBooking 是否预订
     * @param {string}  webSite   网址
     * @param {number}  mtuId     MTU ID
     */
        if (this.VARSION) {
            if (this.VARSION < '2.1.0') {
                if (this.UA === 1 || this.UA === 2) {
                    JS2ObjCBridge.call("goPoiDetail", [poiName, parseFloat(poiNetId), isBooking , webSite]);
                } else if (this.UA === 4) {
                    android.goPoiDetail(poiName, parseFloat(poiNetId), isBooking, webSite);
                }
            }else if(this.VARSION >= '2.1.0' && this.VARSION < '2.2.0'){
                if (this.UA === 1 || this.UA === 2) {
                    JS2ObjCBridge.call("goPoiDetailV2", [poiName, parseFloat(mtuId), isBooking, webSite ]);
                } else if (this.UA === 4) {
                    android.goPoiDetailV2(poiName, parseFloat(mtuId), isBooking, webSite);
                }
            }else{
                if (this.UA === 1 || this.UA === 2) {
                    JS2ObjCBridge.call("goPoiDetailV2", [poiName, mtuId, isBooking ]);
                } else if (this.UA === 4) {
                    android.goPoiDetailV2(poiName, mtuId, isBooking);
                }
            }
        }
    },
    setRButtonGone: function () {
    /**
     * 设置右侧按钮不显⽰
     *
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.setRButtonGone();
            }
        }
    },
    onClickOrderComplete: function (orderId) {
    /**
     * 订单完成按钮
     *
     * @param {number} orderId 订单 ID
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
                JS2ObjCBridge.call('onClickOrderComplete', [orderId]);
            } else if (this.UA === 4) {
                android.onClickOrderComplete(orderId);
            }
        }
    },
    wxPay: function (oid) {
    /**
     * 微信⽀付
     *
     * @param {string} oid 支付 ID
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.wxPay(oid);
            }
        }
    },
    aliPay: function (subject, body, price, oid) {
    /**
     * 支付宝⽀付
     *
     * @param {string} subject 标题
     * @param {string} body    说明
     * @param {string} price   价格
     * @param {string} oid     支付 ID
     */
        if (this.VARSION) {
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                android.aliPay(subject, body, price, oid);
            }
        }
    },



    setHotelName: function (hotelType, name) {
    },
    confirmEvent: function(){
    },
    setNewTime: function (timeType, sTime) {
    },
    setDate: function (date, type) {
    },
    isAliPayApp: function (isSupport) {
    /**
     * 是否⽀持支付宝支付
     *
     * @param {boolean} isSupport 是否支持
     */
    },
    onPageLoad: function () {
    /**
     * 支付宝⽀付
     *
     * @param {string} subject 标题
     * @param {string} body    说明
     * @param {string} price   价格
     * @param {string} oid     支付 ID
     */
        if (this.VARSION) {
            this.goBackApp(goBackFlag);
            this.showContactUs(contactFlag);
            this.showConfirmButton(confirmFlag);
            if(breadtripBannerTitle) this.setTitle(breadtripBannerTitle);
            if (this.UA === 1 || this.UA === 2) {
            } else if (this.UA === 4) {
                if(typeof(android) == "undefined") {
                } else {
                    if(shrFlag == 1) {
                        android.loadShareButton(shr_text,
                            shr_photo,
                            shr_title,
                            shr_summary,
                            shr_image,
                            shr_wechat_title_friend,
                            shr_wechat_summary_friend,
                            shr_wechat_title_circle,
                            shr_wechat_summary_circle,
                            shr_wechat_image);
                    }
                }
            }
        }
    },
};

function setHotelName (hotelType, name) {
    vAppSchema.setHotelName(hotelType, name);
}

function setNewTime (timeType, sTime) {
    vAppSchema.setNewTime(timeType, sTime);
}

function setDate (date, type) {
    vAppSchema.setDate(date, type);
}

function isAliPayApp (isSupport) {
    vAppSchema.isAliPayApp(isSupport);
}
// function onPageLoad() {
    vAppSchema.onPageLoad();
// }